package com.axend.aerosense.user.fragment;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.axend.aerosense.base.fragment.MvvmBaseFragment;
import com.axend.aerosense.base.viewmodel.BaseViewModel;
import com.axend.aerosense.common.util.NotifyUtil;
import com.axend.aerosense.user.R;
import com.axend.aerosense.user.UserSettingActivity;
import com.axend.aerosense.user.databinding.UserSetNoticeFragmentBinding;

public class UserSetNoticeFragment extends MvvmBaseFragment<UserSetNoticeFragmentBinding, BaseViewModel> {

    NotifyUtil notifyUtil;

    public static UserSetNoticeFragment getInstance() {
        UserSetNoticeFragment fragment = new UserSetNoticeFragment();
        return fragment;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        init();
    }

    public void init() {
        notifyUtil = NotifyUtil.getInstance(getContext());
//        boolean isNotifyOpen = notifyUtil.checkNotifySetting();
//        if (isNotifyOpen) {
//            viewDataBinding.userSwitchNotification.setChecked(true);
//        } else {
//            viewDataBinding.userSwitchNotification.setChecked(false);
//        }
//        viewDataBinding.userSwitchNotification.setOnClickListener(v -> {
//            notifyUtil.initClickListener();//进入设置通知界面
//        });
    }


    @Override
    public int getLayoutId() {
        return R.layout.user_set_notice_fragment;
    }

    @Override
    public int getBindingVariable() {
        return 0;
    }

    @Override
    protected BaseViewModel getViewModel() {
        return null;
    }

    @Override
    protected void onRetryBtnClick() {

    }

    @Override
    public void onResume() {
        super.onResume();
        if (viewDataBinding.userSwitchNotification != null) {
//            if (notifyUtil.checkNotifySetting()){
//                viewDataBinding.userSwitchNotification.setOnClickListener(null);
//            }else {
//                viewDataBinding.userSwitchNotification.setOnClickListener(v -> {
//                    notifyUtil.initClickListener();//进入设置通知界面
//                });
//            }
            viewDataBinding.userSwitchNotification.setOnClickListener(v -> {
                notifyUtil.initClickListener();//进入设置通知界面
            });
            viewDataBinding.userSwitchNotification.setChecked(notifyUtil.checkNotifySetting());
        }
        ((UserSettingActivity) getActivity()).setTitle(getString(R.string.user_new_message_notice));
    }
}
